]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
util: rename from utils, avoid RegExp literal
authorDan Winship <danw@gnome.org>
Tue, 30 Nov 2010 16:16:10 +0000 (11:16 -0500)
committerDan Winship <danw@gnome.org>
Thu, 13 Jan 2011 17:14:40 +0000 (12:14 -0500)
Rename imports.misc.utils to imports.misc.util for more consistency
(eg, with shell-util).

Also, use the string-based RegExp() constructor rather than a RegExp
literal, since the literal is extremely difficult to parse correctly,
and confuses emacs and probably other editors and thus messes up
autoindentation, etc.

https://bugzilla.gnome.org/show_bug.cgi?id=635089

js/Makefile.am
js/misc/util.js [new file with mode: 0644]
js/misc/utils.js [deleted file]
js/ui/messageTray.js

index b2975fc2724ccbcf00f15fdeb0c721580035be39..3d87decc977b6e4df358973f01237221e3543883 100644 (file)
@@ -9,7 +9,7 @@ nobase_dist_js_DATA =   \
        misc/gnomeSession.js    \
        misc/params.js          \
        misc/telepathy.js       \
-       misc/utils.js           \
+       misc/util.js            \
        perf/core.js            \
        ui/altTab.js            \
        ui/appDisplay.js        \
diff --git a/js/misc/util.js b/js/misc/util.js
new file mode 100644 (file)
index 0000000..0d1d5c4
--- /dev/null
@@ -0,0 +1,19 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+/* http://daringfireball.net/2010/07/improved_regex_for_matching_urls */
+const _urlRegexp = new RegExp('\b(([a-z][\w-]+:(/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)([^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))', 'gi');
+
+// findUrls:
+// @str: string to find URLs in
+//
+// Searches @str for URLs and returns an array of objects with %url
+// properties showing the matched URL string, and %pos properties indicating
+// the position within @str where the URL was found.
+//
+// Return value: the list of match objects, as described above
+function findUrls(str) {
+    let res = [], match;
+    while ((match = _urlRegexp.exec(str)))
+        res.push({ url: match[0], pos: match.index });
+    return res;
+}
diff --git a/js/misc/utils.js b/js/misc/utils.js
deleted file mode 100644 (file)
index 0b7d6c0..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
-
-/* http://daringfireball.net/2010/07/improved_regex_for_matching_urls */
-const _urlRegexp = /\b(([a-z][\w-]+:(\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)([^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/gi;
-
-// findUrls:
-// @str: string to find URLs in
-//
-// Searches @str for URLs and returns an array of objects with %url
-// properties showing the matched URL string, and %pos properties indicating
-// the position within @str where the URL was found.
-//
-// Return value: the list of match objects, as described above
-function findUrls(str) {
-    let res = [], match;
-    while ((match = _urlRegexp.exec(str)))
-        res.push({ url: match[0], pos: match.index });
-    return res;
-}
index 4188225c91afb894f7040a8a75f297f671fa2959..e085421ef8e716c1b73d8d7631740e5df9f62286 100644 (file)
@@ -16,7 +16,7 @@ const Tweener = imports.ui.tweener;
 const Main = imports.ui.main;
 const BoxPointer = imports.ui.boxpointer;
 const Params = imports.misc.params;
-const Utils = imports.misc.utils;
+const Util = imports.misc.util;
 
 const Gettext = imports.gettext.domain('gnome-shell');
 const _ = Gettext.gettext;
@@ -138,13 +138,13 @@ URLHighlighter.prototype = {
 
         this.actor.clutter_text.set_markup(text);
         /* clutter_text.text contain text without markup */
-        this._urls = Utils.findUrls(this.actor.clutter_text.text);
+        this._urls = Util.findUrls(this.actor.clutter_text.text);
         this._highlightUrls();
     },
 
     _highlightUrls: function() {
         // text here contain markup
-        let urls = Utils.findUrls(this._text);
+        let urls = Util.findUrls(this._text);
         let markup = '';
         let pos = 0;
         for (let i = 0; i < urls.length; i++) {